package com.example.demo.com.example.singleton;

import javax.swing.table.TableRowSorter;

public class ThreadLocalSingleton {
    //私有化构造器
    private ThreadLocalSingleton threadLocalSingleton;

    //jdk实现了线程式的容器单例模式，单线程下安全。多线程不安全
    private static final ThreadLocal<ThreadLocalSingleton> threadLocal = new ThreadLocal<ThreadLocalSingleton>(){
        protected ThreadLocalSingleton initSingleton(){
            return new ThreadLocalSingleton();
        }
    };

    //外部调用方法
    public ThreadLocalSingleton getInstance(){
        return threadLocal.get();
    }

}
